package 树;

import common.TreeNode;

/**
 * @author mazouri
 * @create 2021-05-03 21:39
 */
public class _235_lowestCommonAncestor {
    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
        if (root == null || (root.val-p.val)*(root.val-q.val)<0) {
            return root;
        }

        return lowestCommonAncestor(p.val < root.val ? root.left : root.right, p, q);
    }
}
